package org.caijin.springzookeeper.lock;

import org.caijin.springzookeeper.Id.OrderIdGenerator;

public class ZkLockTest implements Runnable{
    private OrderIdGenerator idGenerator = new OrderIdGenerator();
    private Lock lock = new DistributorLock();

    @Override
    public void run() {
        lock.lock();
        try{
            String orderId = idGenerator.generateOrderId();
            System.out.println("生成订单号 "+orderId);
        }finally {
            lock.unlock();
        }
    }
    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 30; i++) {
            new Thread(new ZkLockTest()).start();
        }
        Thread.currentThread().join();
    }
}
